package de.dhbw.ka.tit09.picsim.ui;

import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.CheckboxCellEditor;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.TableViewer;

import de.dhbw.ka.tit09.picsim.ui.model.SourceTextTableElement;

/**
 * Editing support for the breakpoints column in the GUI.
 * 
 * @author Andreas Bender
 * 
 */
public class BreakpointEditingSupport extends EditingSupport {

	private CellEditor cellEditor;

	/**
	 * Constructor.
	 * 
	 * @param viewer the column viewer
	 */
	public BreakpointEditingSupport(ColumnViewer viewer) {
		super(viewer);
		cellEditor = new CheckboxCellEditor(((TableViewer) viewer).getTable());
	}

	@Override
	protected boolean canEdit(Object arg0) {
		return true;
	}

	@Override
	protected CellEditor getCellEditor(Object element) {
		return cellEditor;
	}

	@Override
	protected Object getValue(Object element) {
		return ((SourceTextTableElement) element).isChecked();
	}

	@Override
	protected void setValue(Object element, Object value) {
		((SourceTextTableElement) element).setChecked((Boolean) value);
	}

}
